home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Xconq 7.0d37 / source / kernel / misc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-02  |  3.7 KB  |  166 lines  |  [TEXT/KAHL]

  1. /* Random definitions used everywhere in Xconq.
  2.    Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994 Stanley T. Shebs.
  3.  
  4. Xconq is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.  See the file COPYING.  */
  8.  
  9. #ifndef TRUE
  10. #define TRUE (1)
  11. #endif
  12. #ifndef FALSE
  13. #define FALSE (0)
  14. #endif
  15.  
  16. /* This is how we do optional prototypes and const decls. */
  17.  
  18. #ifdef MSDOS
  19. #define PROTO(ARGS) ARGS
  20. #define CONST const
  21. #endif
  22.  
  23. #ifndef PROTO
  24. #ifdef __STDC__
  25. #define PROTO(ARGS) ARGS
  26. #else
  27. #define PROTO(ARGS) ()
  28. #endif /* __STDC__ */
  29. #endif /* PROTO */
  30.  
  31. #ifndef CONST
  32. #ifdef __STDC__
  33. #define CONST const
  34. #else
  35. #define CONST
  36. #endif /* __STDC__ */
  37. #endif /* CONST */
  38.  
  39. #ifndef ABS
  40. #define ABS(x) (((x) < 0) ? (0 - (x)) : (x))
  41. #endif
  42.  
  43. #ifndef min
  44. #define min(x,y) (((x) < (y)) ? (x) : (y))
  45. #endif
  46.  
  47. #ifndef max
  48. #define max(x,y) (((x) > (y)) ? (x) : (y))
  49. #endif
  50.  
  51. #define between(lo,n,hi) ((lo) <= (n) && (n) <= (hi))
  52.  
  53. #define flip_coin() (xrandom(257) % 2)
  54.  
  55. #define avg(a,b) (((a) + (b)) / 2)
  56.  
  57. #ifndef isspace
  58. #define isspace(c) ((c) == ' ' || (c) == '\n' || (c) == '\t' || (c) == '\r')
  59. #endif
  60.  
  61. #define lowercase(c) (isupper(c) ? tolower(c) : (c))
  62.  
  63. #define uppercase(c) (islower(c) ? toupper(c) : (c))
  64.  
  65. /* This tests a string to see if it has anything in it. */
  66.  
  67. #define empty_string(s) ((s) == NULL || s[0] == '\0')
  68.  
  69. extern char spbuf[];
  70. extern char tmpbuf[];
  71.  
  72. #ifdef DEBUGGING
  73.  
  74. #ifndef USE_CONSOLE
  75.  
  76. /* Attempt to disable console I/O. */
  77.  
  78. #undef  printf
  79. #define printf abort
  80. #undef  scanf
  81. #define scanf abort
  82.  
  83. #undef  stdin
  84. #define stdin (-1)
  85. #undef  stdout
  86. #define stdout (-1)
  87. #undef  stderr
  88. #define stderr (-1)
  89.  
  90. #endif /* ! USE_CONSOLE */
  91.  
  92. /* Debugging definitions. */
  93.  
  94. #define Dprintf if (Debug) debug_printf
  95. #define DMprintf if (DebugM) debugm_printf
  96. #define DGprintf if (DebugG) debugg_printf
  97.  
  98. #define Dprintlisp(X) if (Debug) fprintlisp(dfp, (X))
  99. #define DMprintlisp(X) if (DebugM) fprintlisp(dmfp, (X))
  100. #define DGprintlisp(X) if (DebugG) fprintlisp(dgfp, (X))
  101.  
  102. /* If the debug flags are not macros, then declare them as globals. */
  103.  
  104. #ifndef Debug
  105. extern int Debug;
  106. #endif
  107. #ifndef DebugM
  108. extern int DebugM;
  109. #endif
  110. #ifndef DebugG
  111. extern int DebugG;
  112. #endif
  113.  
  114. extern FILE *dfp;
  115. extern FILE *dmfp;
  116. extern FILE *dgfp;
  117.  
  118. #else /* DEBUGGING */
  119.  
  120. /* Make defns and calls vanish if possible. */
  121.  
  122. #define Dprintf if (0) debug_printf
  123. #define DMprintf if (0) debugm_printf
  124. #define DGprintf if (0) debugg_printf
  125.  
  126. #define Dprintlisp(X)
  127. #define DMprintlisp(X)
  128. #define DGprintlisp(X)
  129.  
  130. #define Debug (0)
  131. #define DebugM (0)
  132. #define DebugG (0)
  133.  
  134. #define dfp stdout
  135. #define dmfp stdout
  136. #define dgfp stdout
  137.  
  138. #endif /* DEBUGGING */
  139.  
  140. extern char *getenv();
  141.  
  142. extern void init_xrandom PROTO ((int seed));
  143. extern int xrandom PROTO ((int m));
  144. extern int probability PROTO ((int prob));
  145. extern int roll_dice PROTO ((int n));
  146. extern int prob_fraction PROTO ((int n));
  147.  
  148. extern char *xmalloc PROTO ((int amt));
  149. extern void report_malloc PROTO ((void));
  150. extern void tprintf PROTO ((char *buf, char *str, ...));
  151. extern void tnprintf PROTO ((char *buf, int n, char *str, ...));
  152. extern char *copy_string PROTO ((char *str));
  153. extern int iindex PROTO ((int ch, char *str));
  154. extern long idifftime PROTO ((time_t t1, time_t t0));
  155. extern void case_panic PROTO ((char *str, int var));
  156. extern int isqrt PROTO ((int i));
  157. extern void profile_printf PROTO ((char *str, ...));
  158. extern void debug_printf PROTO ((char *str, ...));
  159. extern void debugm_printf PROTO ((char *str, ...));
  160. extern void debugg_printf PROTO ((char *str, ...));
  161.  
  162. extern void vtprintf PROTO ((char *buf, char *str, va_list ap));
  163.  
  164. extern void make_pathname PROTO ((char *path, char *name, char *extn,
  165.                   char *pathbuf));
  166.